package com.pragati.util;
/**
*
* @author ravik
*/
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Properties;
public class fetchfromCloud {
	/*
public static void main(String args[])
	{
		fetchfromCloud ffc=new fetchfromCloud();
		//ffc.connectCloud();
		String temp=ffc.getPhone("ravi");
		System.out.println(temp);
		
	}

*/
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
Connection con = null;
Statement stmt = null;
ResultSet rs = null;
private void connectCloud(){
	try
	{
	//System.out.println("before 1...");
	Class.forName("com.zoho.cloudsql.jdbc.ZohoReportsDriver");
	//System.out.println("after 1...");
	Properties conProps = new Properties();
	//# Zoho API Key : 45813be1671973a30b5b2048872b47e2
	//# Secretkey : e68b1d28b632fc5fc3ad6c824277fba3

	conProps.put("ZOHO_API_KEY","45813be1671973a30b5b2048872b47e2");

	// Zoho username to login to Zoho service
	conProps.put("user","vtr");

	// Zoho password to login to Zoho service
	conProps.put("password","matrix");

	
	/* Important Note: Connection is single threaded in Zoho Reports */

	con = DriverManager.getConnection("http://reports.zoho.com/" +
	"api/vtr/vtr",conProps);
	stmt = con.createStatement();

	}
	catch(SQLException se)
	{
	// handle any errors
	System.out.println("SQLException: " + se.getMessage());
	System.out.println("Zoho Reports Error code: " + se.getErrorCode());
	}
	catch(java.lang.ClassNotFoundException e)
	{
		System.out.println("Class not found");
	}
	catch(Exception e)
	{
	// handle the exception
	    System.out.println("Exception: " + e.getMessage());
	}
	
}
@SuppressWarnings("finally")
public String getPhone (String alumniname){
	this.connectCloud();
	alumniname.trim();
	String sql ="select cellphone from jjcetalumni where firstname='"+alumniname+"'";
	//System.out.println(sql);
	String phone=null;
	try
	{
	rs = stmt.executeQuery(sql);
	while (rs.next()) {

	    phone=rs.getString(1);
	  
	   // System.out.println("Name "+name);
	               
	}
	}
	catch(SQLException se)
	{
	// handle any errors
	System.out.println("SQLException: " + se.getMessage());
	System.out.println("Zoho Reports Error code: " + se.getErrorCode());
	}
	catch(Exception e)
	{
	// handle the exception
	    System.out.println("Exception: " + e.getMessage());
	}
	finally
	{
	if(rs != null)
	{
	try
	{
	rs.close();
	}
	catch(SQLException sqlEx) { } // ignore
	}
	if(stmt != null)
	{
	try
	{
	stmt.close();
	}
	catch (SQLException sqlEx) { } // ignore
	}
	if(con != null)
	{
	try
	{
	con.close();
	}
	catch (SQLException sqlEx) { } // ignore
	}
	if (phone==null) phone="No result";
	  return(phone);
}

}
}